package com.bjgzy.courselive.di.module;


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.bjgzy.courselive.mvp.contract.CourseListContract;
import com.bjgzy.courselive.mvp.model.CourseListModel;
import com.bjgzy.module_couselive.R;
import com.blankj.utilcode.util.ObjectUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.CourseListData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.FragmentScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-8-27 19:18:09
 */
@Module
public class CourseListModule {
    private CourseListContract.View view;

    /**
     * 构建CourseListModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public CourseListModule(CourseListContract.View view) {
        this.view = view;
    }

    @FragmentScope
    @Provides
    CourseListContract.View provideCourseListView() {
        return this.view;
    }

    @FragmentScope
    @Provides
    CourseListContract.Model provideCourseListModel(CourseListModel model) {
        return model;
    }

    @FragmentScope
    @Provides
    List<CourseListData> provideLists() {
        return new ArrayList<>();
    }

    @FragmentScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager(CourseListContract.View view) {
        return new LinearLayoutManager(view.getActivity());
    }

    @FragmentScope
    @Provides
    BaseQuickAdapter<CourseListData, AutoBaseViewHolder> providerAdapter(List<CourseListData> lists) {
        return new BaseQuickAdapter<CourseListData, AutoBaseViewHolder>(R.layout.courselive_rv_item_direct, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, CourseListData item) {
                TextView tvStatus = helper.getView(R.id.tv_status);
                helper.setText(R.id.tv_title, item.getTitle());
                item.setParentId(view.getParentId());
                helper.setText(R.id.tv_price, ObjectUtils.isEmpty(item.getPrice()) ? "¥0" : "¥" + item.getPrice());
                tvStatus.setText(item.getPlayInfo());
            }
        };

    }
}